package com.sany.taskmanager;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.sany.taskmanager.manager.DataManager;
import com.sany.taskmanager.util.PreferenceUtil;

/**
 * 自定义Application
 */
public class TaskManagerApplication extends Application {

    private Context mContext;
    private static TaskManagerApplication app;
    private Activity mCurrentActivity;

    public static TaskManagerApplication getInstance() {
        return app;
    }

    public Context getContext() {
        return mContext;
    }

    public Activity getCurrentActivity() {
        return mCurrentActivity;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        mContext = getApplicationContext();
        PreferenceUtil.init(this);
        DataManager.getInstance().init();
        initLifeCycle();
    }

    private void initLifeCycle() {
        registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
                mCurrentActivity = activity;
            }

            @Override
            public void onActivityStarted(@NonNull Activity activity) {

            }

            @Override
            public void onActivityResumed(@NonNull Activity activity) {
                mCurrentActivity = activity;
            }

            @Override
            public void onActivityPaused(@NonNull Activity activity) {

            }

            @Override
            public void onActivityStopped(@NonNull Activity activity) {

            }

            @Override
            public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {

            }

            @Override
            public void onActivityDestroyed(@NonNull Activity activity) {

            }
        });
    }
}
